package bavaria.hightech.buchung;

import bavaria.hightech.geld.Money;
import bavaria.hightech.geld.Waehrung;

public class Buchungsliste {

	public Buchung first;
	public Buchung position;
	
	public Buchungsliste(){
		first = new Buchung("Erste Zeile: ", null);
		position = null;
	}
	
	
	public void add(String buchungstext, Money money){
		Buchung buchung = new Buchung(buchungstext, money);
		if (first.next == null){
			position = buchung;
			first.next = position;
			position.next = null;
		}
		else if (position.next == null){
			position.next = buchung;
			position = position.next;
			position.next = null;
		}
		else if (position.next != null){
			while(position.next != null)
				next();
			position.next = buchung;
			position = position.next;
			position.next = null;
			System.out.println(position);	
		}
		
	}
	
	public void clear(){
		first.next = null;
		position = first.next;
	}
	
	public Buchung next(){
		position = position.next;
		return position;
	}
	
	public void resetIteration(){
		position = first.next;
	}
	
	
	
	public static void main(String[] args){
		Buchungsliste liste = new Buchungsliste();
		
		Money money = new Money(100, Waehrung.EUR);
		Money money1 = new Money(200, Waehrung.EUR);
		Money money2 = new Money(300, Waehrung.EUR);
		Money money3 = new Money(400, Waehrung.EUR);
		
		liste.add("Buchung", money);
		liste.add("Buchung2", money1);
		liste.add("Buchung3", money2);
		
		liste.resetIteration();
		
		System.out.println();
		
		while(liste.position != null){
			System.out.println(liste.position.money.betrag);
			liste.next();
		}
		
		liste.resetIteration();
		System.out.println();
		liste.add("Buchung4", money3);
		System.out.println();
		liste.resetIteration();
		
		while(liste.position != null){
			System.out.println(liste.position);
			liste.next();
		}
		
		liste.clear();
		
		while(liste.position != null){
			System.out.println(liste.position);
			liste.next();
		}
		
		
	}
	
}

